﻿using Abp.Domain.Repositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyCompanyName.AbpZeroTemplate.Prm.Project
{
    public class ProjectManager : AbpZeroTemplateDomainServiceBase
    {
        public Abp.Runtime.Session.IAbpSession AbpSession { get; set; }
        public IRepository<ProjectInfo, int> projectRepository { get; private set; }
        public IRepository<ProjectProgress, int> projectProgressRepository { get; private set; }
        public IRepository<ProjectTeam, int> projectTeamRepository { get; private set; }
        public IRepository<ProjectRoleInfo, int> projectRoleInfoRepository { get; private set; }
        public IRepository<TeamComment, int> teamCommentRepository { get; private set; }
        public IRepository<ProjectDocmeut, int> projectDocmeutRepository { get; private set; }
        public IRepository<ProjectDocmeutVersion, int> projectDocmeutVersionRepository { get; private set; }
        public IRepository<ProjectDocType, int> projectDocTypeRepository { get; private set; }

        public IRepository<Topic, int> topicRepository { get; private set; }
        public IRepository<Reply, int> replyRepository { get; private set; }


        public ProjectManager(
            IRepository<ProjectInfo, int> _projectRepository,
            IRepository<ProjectProgress, int> _projectProgressRepository,
            IRepository<ProjectTeam, int> _projectTeamRepository,
            IRepository<ProjectRoleInfo, int> _projectRoleInfoRepository,
            IRepository<TeamComment, int> _teamCommentRepository,
            IRepository<ProjectDocmeut, int> _projectDocmeutRepository,
            IRepository<ProjectDocType, int> _projectDocTypeRepository,
            IRepository<ProjectDocmeutVersion, int> _projectDocmeutVersionRepository,
            IRepository<Topic, int> _topicRepositor,
            IRepository<Reply, int> _replyRepository)
        {
            projectRepository = _projectRepository;
            projectProgressRepository = _projectProgressRepository;
            projectTeamRepository = _projectTeamRepository;
            projectRoleInfoRepository = _projectRoleInfoRepository;
            teamCommentRepository = _teamCommentRepository;
            projectDocmeutRepository = _projectDocmeutRepository;
            projectDocTypeRepository = _projectDocTypeRepository;
            projectDocmeutVersionRepository = _projectDocmeutVersionRepository;
            topicRepository = _topicRepositor;
            replyRepository = _replyRepository;
            AbpSession = Abp.Runtime.Session.NullAbpSession.Instance;
        }



        /// <summary>
        /// 设置项目进度
        /// </summary>
        /// <param name="progress"></param>
        /// <returns></returns>
        public async Task SetProjectProgress(ProjectProgress progress)
        {
            await projectProgressRepository.InsertAsync(progress);
        }


        /// <summary>
        /// 设置项目成员
        /// </summary>
        /// <param name="roleId"></param>
        /// <param name="users"></param>
        /// <returns></returns>
        public async Task SetProjectTeam(int projectId, int roleId, List<int> users)
        {
            foreach (var item in users)
            {
                var pt = new ProjectTeam() { ProjectId = projectId, ProjectRoleId = roleId, UserId = item };
                await projectTeamRepository.InsertAsync(pt);
            }
        }



    }
}
